unit frDepartmentPage;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, frBillPage, cxGraphics, cxControls, cxLookAndFeels,
  cxLookAndFeelPainters, dxCustomTileControl, dxTileControl, cxClasses, ExtCtrls;

type
  TfrmDepartmentPage = class(TfrmBillPage)
    dxTileControl1: TdxTileControl;
    dxTileControl1Group1: TdxTileControlGroup;
    dxTileControl1Item2: TdxTileControlItem;
    dxTileControl1Item3: TdxTileControlItem;
    dxTileControl1Item4: TdxTileControlItem;
    pnlMain: TPanel;
    procedure dxTileControl1Item2Click(Sender: TdxTileControlItem);
    procedure dxTileControl1Item4Click(Sender: TdxTileControlItem);
    procedure dxTileControl1Item3Click(Sender: TdxTileControlItem);
  private
    { Private declarations }
    procedure ShowEmbedForm(AFormClass: TFormClass; AOwner: TComponent; var AForm: TForm);    
    procedure HideAll;
  public
    { Public declarations }
    destructor Destroy; override;

  end;

var
  frmDepartmentPage: TfrmDepartmentPage;

implementation

uses
  fBillManager, fEmployeeLocation, tools;

{$R *.dfm}
destructor TfrmDepartmentPage.Destroy;
begin
  FreeAndNil(fmBillManager);
  FreeAndNil(fmEMployeeLocation);
  inherited;
end;

procedure TfrmDepartmentPage.ShowEmbedForm(AFormClass: TFormClass; AOwner: TComponent; var AForm: TForm);
begin
  if AForm = nil then
  begin
    AForm := AFormClass.Create(AOwner);
    AForm.Align := alClient;
    AForm.BorderStyle := bsNone;
    AForm.Parent := TWinControl(pnlMain);
    AForm.Visible := True;
  end
  else
  begin
    AForm.Align := alClient;
    AForm.BorderStyle := bsNone;
    AForm.Parent := TWinControl(pnlMain);
    AForm.Visible := True;
  end;
end;

procedure TfrmDepartmentPage.dxTileControl1Item3Click(
  Sender: TdxTileControlItem);
begin
  HideAll;
end;

procedure TfrmDepartmentPage.dxTileControl1Item4Click(
  Sender: TdxTileControlItem);
begin
  HideAll;
  ShowEmbedForm(TfmEmployeeLocation, self, TForm(fmEmployeeLocation));
end;

procedure TfrmDepartmentPage.HideAll;
begin
  if fmEmployeeLocation <> nil then
    fmEmployeeLocation.Visible := False;
  if fmBillManager <> nil then
    fmBillManager.Visible := False;
end;

procedure TfrmDepartmentPage.dxTileControl1Item2Click(
  Sender: TdxTileControlItem);
begin
  HideAll;
  ShowEmbedForm(TfmBillManager, self, TForm(fmBillManager));

end;

end.
